package ab.mes.service.impl;

import ab.mes.entity.firstCheckRecords;
import ab.mes.entity.orderFQARecords;
import ab.mes.mapper.firstCheckRecordsMapper;
import ab.mes.mapper.orderFQARecordsMapper;
import ab.mes.service.orderFQARecordsService;
import ab.mes.tools.Result;
import ab.mes.tools.firstCheckRecordsConditions;
import ab.mes.tools.orderFQARecordsConditions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class orderFQARecordsServiceImpl implements orderFQARecordsService {
    @Autowired
    private ab.mes.mapper.orderFQARecordsMapper orderFQARecordsMapper;

    //查询所有订单FQA历史记录
    @Override
    public Result selectAll() {
        Result result = new Result();
        result.getMap().put("orderFQARecords",orderFQARecordsMapper.selectList(null));
        return result;
    }

    //根据起止日期、订单编号、生产序号查询订单FQA历史记录
    @Override
    public Result select1(orderFQARecordsConditions conditions) {
        Result result = new Result();
        QueryWrapper<orderFQARecords> wrapper = new QueryWrapper<>();
        //订单编号不为空时，才进行查询
        wrapper.eq(conditions.getOrderNoOrProductionNo()!="","order_No",
                conditions.getOrderNoOrProductionNo());
        wrapper.or();
        //生产序号不为空时，才进行查询
        wrapper.eq(conditions.getOrderNoOrProductionNo()!="","production_No",
                conditions.getOrderNoOrProductionNo());
        //当审批开始时间不为空时，才进行查询 ge：大于等于
        wrapper.ge(conditions.getStartDate() != null,"audit_Time",
                conditions.getStartDate());
        //当审批结束时间不为空时，才进行查询 le：小于等于
        wrapper.le(conditions.getEndDate()!=null,"audit_Time",
                conditions.getEndDate());
        List<orderFQARecords> recordsList = orderFQARecordsMapper.select1(wrapper);
        if(recordsList.size() == 0){
            result.setErrorMessage("无符合条件的信息");
        }else {
            result.getMap().put("orderFQARecords",recordsList);
        }
        return result;
    }
}
